#!/usr/bin/env python 
# -*- coding: utf-8 -*-
# @Time    : 2023/5/4 23:08
# @Author  : Junzhao
# @File    : 查.py
# @Software: PyCharm
import pymysql

# 链接MySQL
conn = pymysql.connect(host="127.0.0.1", port=3306, user='root', password="", charset='utf8', db='unicom')
cursor = conn.cursor(cursor=pymysql.cursors.DictCursor)

# 还可以：
sql = "select * from admin"
cursor.execute(sql)
data_lt = cursor.fetchall()
# print("{:<2}\t{:<15}{:<20}{:<11}".format("id", "username", "password", "mobile"))
# for i in data_lt:
#     print("{:<2}\t{:<15}{:<20}{:<11}".format(i[0], i[1], i[2], i[3], ))
print("{:<2}\t{:<15}{:<20}{:<11}".format("id", "username", "password", "mobile"))
for i in data_lt:
    print("{:<2}\t{:<15}{:<20}{:<11}".format(i["id"], i["username"], i["password"], i["mobile"], ))

# print(data_lt)

# 关闭连接
cursor.close()
conn.close()
